<template>
  <el-tree
    :data="data"
    :props="defaultProps"
    accordion
    @node-click="handleNodeClick"
  >
    <span
      class="custom-tree-node"
      slot-scope="{ node, data }"
    >
      <span>
        <i :class="data.icon"></i>{{ node.label }}
      </span>
    </span>
  </el-tree>
</template>

<script>
export default {
  data() {
    return {
      data: [{
        id: 1,
        label: '一级 1',
        icon: 'el-icon-success',
        children: [{
          id: 11,
          label: '二级 1-1',
          icon: 'el-icon-success'
        }]
      }, {
        id: 2,
        label: '一级 2',
        icon: 'el-icon-success',
        children: [{
          id: 21,
          label: '二级 2-1',
          icon: 'el-icon-success'
        }, {
          id: 22,
          label: '二级 2-2',
          icon: 'el-icon-success'
        }]
      }, {
        id: 3,
        label: '一级 3',
        icon: 'el-icon-success',
        children: [{
          id: 31,
          label: '二级 3-1',
          icon: 'el-icon-success'
        }, {
          id: 32,
          label: '二级 3-2',
          icon: 'el-icon-success'
        }]
      }],
      defaultProps: {
        children: 'children',
        label: 'label'
      }
    }
  },
  methods: {
    handleNodeClick(data) {
      console.log(data)
    }
  }
}
</script>
